package com.demo.service.impl;

import com.demo.common.utils.AuthUtils;
import com.demo.vo.ActivityRemarkVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.demo.mapper.ActivityRemarkMapper;
import com.demo.entity.ActivityRemark;
import com.demo.service.ActivityRemarkService;

import java.util.Date;
import java.util.List;

@Service
public class ActivityRemarkServiceImpl extends ServiceImpl<ActivityRemarkMapper, ActivityRemark>
        implements ActivityRemarkService {
    @Autowired
    public ActivityRemarkMapper activityRemarkMapper;

    @Override
    public PageInfo<ActivityRemarkVO> queryActivityRemarkPageByActivityId(Integer activityId, Integer current, Integer pageSize) {

        // 设置分页
        PageHelper.startPage(current, pageSize);
        // 查询数据
        List<ActivityRemarkVO> list = activityRemarkMapper.selectActivityRemarkListActivityId(activityId);
        return new PageInfo<>(list);
    }

    @Override
    public boolean save(ActivityRemark activityRemark) {
        activityRemark.setCreateBy(AuthUtils.getLoginUserId());
        activityRemark.setCreateTime(new Date());
        activityRemark.setDeleted(0);
        return activityRemarkMapper.insert(activityRemark) > 0;

    }

    @Override
    public boolean updateById(ActivityRemark activityRemark) {
        activityRemark.setEditBy(AuthUtils.getLoginUserId());
        activityRemark.setEditTime(new Date());
        return activityRemarkMapper.updateById(activityRemark) > 0 ;

    }
}
